﻿@{
    ViewBag.Title = "深圳凡曦电子商务有限公司";
    Layout = "~/Views/Shared/MyLayout.cshtml";
}

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link href="~/Content/bootstrap/css/style.css" rel="stylesheet" />
<link href="~/Content/bootstrap/css/base.css" rel="stylesheet" />
<link href="~/Scripts/datejs/datecss.css" rel="stylesheet" />
<script src="~/Scripts/jquery-2.1.1.min.js"></script>
<link href="~/Scripts/datejs/datecss.css" rel="stylesheet" />
<link href="~/Scripts/css/gloabcss.css" rel="stylesheet" />
<script src="~/Scripts/layer/layer.js"></script>
<script src="~/Scripts/Common.js"></script>
<script src="~/Scripts/layPage/laypage.js"></script>
<script src="~/Scripts/datejs/jquery-ui-1.10.4.custom.min.js"></script>
<script src="~/Scripts/datejs/jquery-ui-timepicker-addon.js"></script>
<style>
    input {
        width: 12%;
        height: 25px;
        margin-left: 15px;
    }

    .span8 input {
        width: 30%;
    }

    .container-fluid {
        margin: 0;
        padding: 0;
    }

    #edit_agency p {
        padding-top: 15px;
    }

    table tr td {
        padding: 12px 0px 12px 0px;
    }

    #Paging {
        position: absolute;
        float: right;
        left: 60%;
        margin-top: 4%;
    }

</style>
<script>
    var hiden_type = 1;
    //窗体加载
    $(function () {
        hiden_type = $("#hiden_type").val();
        // Agent();
        GetCategory();
        GetLevel();
        GetSalesMan();
        SearchList();
        $("input[name='start_Time']").datetimepicker();
        $("input[name='end_Time']").datetimepicker();
    })
    //模糊查询
    function queryshouquan(pageindex, pagesize) {
        var pagecount;
        var name = $('#agency_name').val();
        var mobile = $('#moblie').val();
        var level_id = $('#sel_level').val();
        var state = $("#sel_state").val();
        $.ajax({
            type: "GET",
            url: "/Sqauthorization/query_Sqauthorization",
            data: { "pageindex": pageindex, "pagesize": pagesize, "Name": name, "mobile": mobile, "level_id": level_id, "state": state },
            dataType: "json",
            async: false,
            success: function (data) {
                $("#tab_product  tr:not(:first)").remove();
                pagecount = data.Pagecount;
                if (data.MessageCode == "0") {
                    if (data.Shouquanlist != null) {
                        if (hiden_type == 1) {
                            $.each(data.Shouquanlist, function (i, n) {
                                var s_html = n.state == "0" ? "待审核" : n.state == "1" ? "<a href=\"" + n.sq_img + "\" target=\"_blank\" title=\"点击可以查看授权证书\">已同意</a>" : "已拒绝";
                                var ht = n.state == "0" ? "<input type='button' value='同意' onclick='authorization(this,"+n.id+",\"yes\")' style='width:30px;height:22px; border:none;color:#55AC58;margin-left:5px;cursor:pointer;'/><input type='button' value='拒绝' onclick='authorization(this," + n.id + ",\"no\")' style='width:30px;height:22px; border:none;color:#55AC58;margin-left:5px;cursor:pointer;'/>" : "";
                                var html = "<tr class='rep-tab-tr1 back-f9f'>" +
                                    "<td>" + n.name + "</td>" +
                                    "<td>" + n.level_name + "</td>" +
                                    "<td>" + n.mobile + "</td>" +
                                    "<td>" + formatDateTime(n.start_time) + "</td>" +
                                    "<td>" + formatDateTime(n.end_time) + "</td>" +
                                    "<td>" + s_html + "</td>" +
                                    "<td style=\"text-align:left;\">" + ht + "<input type='button' value='删除' onclick='del(this," + n.id + ")' style='width:30px;height:22px; border:none;color:#55AC58;'/></td></tr>";
                                $("#tab_product").append(html);
                            });


                        } else {
                            $.each(data.Shouquanlist, function (i, n) {
                                var s_html = n.state == "0" ? "待审核" : n.state == "1" ? "<a href=\"" + n.sq_img + "\" target=\"_blank\" title=\"点击可以查看授权证书\">已同意</a>" : "已拒绝";
                                var html = "<tr class='rep-tab-tr1 back-f9f'>" +
                                    "<td>" + n.name + "</td>" +
                                    "<td>" + n.level_name + "</td>" +
                                    "<td>" + n.mobile + "</td>" +
                                    "<td>" + formatDateTime(n.start_time) + "</td>" +
                                    "<td>" + formatDateTime(n.end_time) + "</td>" +
                                    "<td>" + s_html + "</td>" +
                                    "<td style=\"text-align:left;\"></td></tr>";
                                $("#tab_product").append(html);
                            });

                        }
                        
                    } else {
                        layer.msg("暂无数据！");

                    }
                } else {
                    layer.msg("查询失败,请稍后再试！");
                }
            }
        })
        return pagecount;
    }
    //分页
    function SearchList() {
        var pagecount = queryshouquan(1, 8);
        //好像很实用的样子，后端的同学再也不用写分页逻辑了。
        laypage({
            cont: 'pager',
            pages: pagecount, //可以叫服务端把总页数放在某一个隐藏域，再获取。假设我们获取到的是18
            skip: true, //是否开启跳页
            skin: '#5c86b2',
            curr: function () { //通过url获取当前页，也可以同上（pages）方式获取
                var page = location.search.match(/page=(\d+)/);
                return page ? page[1] : 1;
            }(),
            jump: function (e, first) { //触发分页后的回调
                if (e.pages > 1) { $('#pagercount').html('共' + e.pages + '页'); } else { $('#pagercount').hide(); }
                $('.laypage_skip').val(e.curr);
                if (!first) { //一定要加此判断，否则初始时会无限刷新
                    queryshouquan(e.curr, 8);
                }
            }
        });
    }
    //逻辑删除
    function del(obj, id) {
        layer.open({
            type: 1,
            btn: ['确定', '取消'],
            title: '删除',
            skin: "layui-layer-molv",
            area: ['200px', '135px'],
            shade: 0.3,
            content: "你确定要删除吗",
            btn1: function () {
                $.ajax({
                    type: "POST",
                    url: "/Sqauthorization/delete",
                    dataType: "json",
                    data: { "id": id },
                    success: function (data) {
                        // layer.alert(JSON.stringify(data));
                        if (data.MessageCode == "0") {
                            layer.msg("删除成功！");
                            setTimeout(function () {
                                window.location.reload();
                            }, 2000)
                        } else {
                            layer.msg("删除失败！");
                        }
                    }
                });
            },
            btn2: function () {
                layer.close();
            }
        });
    }
    //下拉框信息
    function Agent() {
        $.ajax({
            type: "GET",
            url: "/Index/GetTypeName",
            dataType: "json",
            data: {},
            success: function (data) {
                //layer.alert(JSON.stringify(data));
                $.each(data, function (i, n) {
                    $("#sel_level").append("<option value='" + n.id + "'>" + n.type_name + "</option>");
                });
            }
        });
    }
    ////授权和放弃授权
    //function authorization(obj, id, opea) {
    //    var title = opea == "yes" ? "同意更新" : "拒绝更新";
    //    var con = opea == "yes" ? "是否同意更新授权时间?" : "是否拒绝更新授权时间?";
    //    var state = opea == "yes" ? 1 : 2;
    //    layer.open({
    //        type: 1,
    //        btn: ['确定', '取消'],
    //        title: title,
    //        skin: "layui-layer-molv",
    //        area: ['200px', '135px'],
    //        shade: 0.3,
    //        content: con,
    //        btn1: function () {
    //            $.ajax({
    //                type: "POST",
    //                url: "/Sqauthorization/Authorization",
    //                data: { "id": id, "state": state },
    //                dataType: "json",
    //                async: false,
    //                success: function (data) {
    //                    //alert(JSON.stringify(data));
    //                    if (data="0") {
    //                        layer.msg("操作成功!");
    //                        setTimeout(function () {
    //                            window.location.reload();
    //                        }, 2000)
    //                    } else {
    //                        layer.alert("操作失败！");
    //                    }
    //                }
    //            });
    //        },
    //        btn2: function () {

    //            layer.close();
    //        }
    //    });
    //}
    //查询出要编辑的人的信息
    function GetAgency(agency_id,id) {
        alert(agency_id); alert(id);
        $.ajax({
            type: "GET",
            url: "/Sqauthorization/GetAgency",
            data: { "agency_id": agency_id, "oper": "shouquan", "auid": id },
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.MessageCode == "0") {
                    var st = formatDateTime(data.model.start_time);
                    $("#div_pwd").show();
                    $("#txt_pwd").val(data.pwd);
                    $("#txt_name").val(data.model.name);
                    $("#txt_companyName").val(data.model.company_name);
                    $("#txt_contract_name").val(data.model.contract_name);
                    $("#txt_mobile").val(data.model.mobile);
                    $("#txt_qqCode").val(data.model.qq);
                    $("#txt_wxopen").val(data.model.wx_openid);
                    $("#txt_wwCode").val(data.model.ww_code);
                    $("#txt_idcard").val(data.model.id_card);
                    $("#txt_shopurl").val(data.model.shop_url);
                    $("#txt_start_time").val(st);
                    $("#sel_Category").val(data.model.category_id);
                    $("#sel_Level").val(data.model.level_id);
                    $("#sel_salesman").val(data.model.salesmanid);

                    $("input[name='l_shouquan']").each(function (m, k) {
                        if ($(this).val() == data.model.state) {

                            $("input[name='l_shouquan']").eq(m).attr("checked", "checked");
                        }

                    })
                    $("input[name='l_shenhe']").each(function (m, k) {

                        if ($(this).val() == data.model.shState) {

                            $("input[name='l_shenhe']").eq(m).attr("checked", "checked");
                        }

                    })
                    $("input[name='l_fz']").each(function (m, k) {

                        if ($(this).val() == data.model.share_state) {

                            $("input[name='l_fz']").eq(m).attr("checked", "checked");
                        }

                    })
                }
            }
        });
    }

    //授权和放弃授权
    function authorization(obj, id, opea) {
  
        var title = opea == "yes" ? "同意更新" : "拒绝更新";
        var con = opea == "yes" ? "是否同意更新授权时间?" : "是否拒绝更新授权时间?";
        var state = opea == "yes" ? 1 : 2;
        layer.open({
            type: 1,
            btn: ['确定', '取消'],
            title: title,
            skin: "layui-layer-molv",
            area: ['200px', '135px'],
            shade: 0.3,
            content: con,
            btn1: function () {
                $.ajax({
                    type: "POST",
                    url: "/Sqauthorization/Authorization",
                    data: { "id": id, "state": state },
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        //alert(JSON.stringify(data));
                        if (data = "0") {
                            layer.msg("操作成功!");
                            setTimeout(function () {
                                window.location.reload();
                            }, 2000)
                        } else {
                            layer.alert("操作失败！");
                        }
                    }
                });
            },
            btn2: function () {

                layer.close();
            }
        });
    }
</script>

<input type="hidden" value="@ViewData["hiden_type"]" id="hiden_type" />
<div class="rightoverflow">
    <div class="ove-hid">
        <div class="wid-100 cor-4d4 fon-siz20 lin-hei60 bor-bot999">
            <div class="flo-lef">&nbsp;&nbsp;&nbsp;&nbsp;<span><i class="fa fa-gear"></i></span><span>授权记录</span></div>
        </div>
    </div>
    <div class="ove-hid">
        <div class="Rep-main wid-100 mag-top50">
            <div style=" margin-left: 10%;display:none;" >
                <input type="text" placeholder="  输入客户名称" par="par" id="agency_name" />
                <input type="text" placeholder="  输入手机号" par="par" id="moblie" />
                客户类别&nbsp;:<select class="selects" id="sel_level" par="par">
                    <option value="-1">请选择</option>
                </select>
                审核状态&nbsp;:<select class="selects" id="sel_state" par="par">
                    <option value="-1">请选择</option>
                    <option value="0">待审核</option>
                    <option value="1">已审核</option>
                    <option value="2">已拒绝</option>
                </select>
                <input type="button" value="查询" onclick="SearchList();" style=" color: white; border: none; width: 10%; height: 30px; font-weight: bold; margin-bottom: 10px; background-color: #FF8302; " />
            </div>
            <div class="pro-div" id="con_two_1">
                <table class="rep-tab wid-100 cor-4d4 tex-ali" id="tab_product">
                    <thead>
                        <tr>
                            <td>客户名称</td>
                            <td>特约经销商</td>
                            <td>手机号码</td>
                            <td>申请时间</td>
                            <td>到期时间</td>
                            <td>申请状态</td>
                            <td>操作</td>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>

<div id="add_agency" style="display:none;">
    <div class="divLeft"> <div class="divSpan"><span>商家名称:</span></div><div class="divInput"><input type="text" id="txt_name" placeholder="请输入商家名称" class="required" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>公司名称:</span></div><div class="divInput"><input type="text" id="txt_companyName" placeholder="请输入公司名称" class="required" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>联系人:</span></div><div class="divInput"><input type="text" id="txt_contract_name" placeholder="请输入联系人姓名" class="required" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>手机号:</span></div><div class="divInput"><input type="text" id="txt_mobile" placeholder="请输入正确的手机号" class="tel required" /></div></div>
    <div class="divLeft" id="div_pwd" style="display:none;"> <div class="divSpan"><span>密码:</span></div><div class="divInput"><input type="text" id="txt_pwd" disabled="disabled" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>QQ号:</span></div><div class="divInput"><input type="text" id="txt_qqCode" placeholder="请输入QQ号" class="required" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>微信号:</span></div><div class="divInput"><input type="text" id="txt_wxopen" placeholder="请输入微信号" class="required" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>旺旺号:</span></div><div class="divInput"><input type="text" id="txt_wwCode" placeholder="请输入旺旺号" class="required" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>身份证号:</span></div><div class="divInput"><input type="text" id="txt_idcard" placeholder="请输入正确身份证号" class="sfz" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>店铺网址:</span></div><div class="divInput"><input type="text" id="txt_shopurl" placeholder="请输入店铺网址" class="required" /></div></div>
    <div class="divLeft">
        <div class="divSpan"><span>客户级别:</span></div><div class="divInput">
            <select style="margin-left: 15px;width: 85%;height: 25px;" id="sel_Level">
                <option value="-1">请选择</option>
            </select>
        </div>
    </div>
    <div class="divLeft">
        <div class="divSpan"><span>客户类别:</span></div><div class="divInput">
            <select style="margin-left: 15px;width: 85%;height: 25px;" id="sel_Category">
                <option value="-1">请选择</option>
            </select>
        </div>
    </div>
    <div class="divLeft">
        <div class="divSpan"><span>业务员:</span></div><div class="divInput">
            <select style="margin-left: 15px;width: 85%;height: 25px;" id="sel_salesman">
                <option value="-1">请选择</option>
            </select>
        </div>
    </div>
    <div class="divLeft"> <div class="divSpan"><span>授权时间(始):</span></div><div class="divInput"><input type="text" name="start_time" id="txt_start_time" placeholder="请选择授权开始时间" class="required" /></div></div>

    <div class="divLeft">
        <div class="divSpan"><span>是否授权:</span></div><div class="divInput">
            <input class="huodongchk" type="radio" name="l_shouquan" id="l_sq" value="1" style="width:20px; height:20px;" /><label for="l_sq">授权</label>
            <input class="huodongchk" type="radio" name="l_shouquan" id="l_fq" value="2" style="width: 20px; height: 20px;" /><label for="l_fq">放弃</label>
        </div>
    </div>
    <div class="divLeft">
        <div class="divSpan"><span>是否审核:</span></div><div class="divInput">
            <input class="huodongchk" type="radio" name="l_shenhe" id="l_sh" value="1" style="width:20px; height:20px;" /><label for="l_sh">审核</label>
            <input class="huodongchk" type="radio" name="l_shenhe" id="l_bsh" value="2" style="width: 20px; height: 20px;" /><label for="l_bsh">不审核</label>
        </div>
    </div>
    <div class="divLeft">
        <div class="divSpan"><span>是否发展下级:</span></div><div class="divInput">
            <input class="huodongchk" type="radio" name="l_fz" id="l_fz" value="1" style="width:20px; height:20px;" /><label for="l_fz">是</label>
            <input class="huodongchk" type="radio" name="l_fz" id="l_bfz" value="0" style="width: 20px; height: 20px;" /><label for="l_bfz">否</label>
        </div>
    </div>
</div>


<style type="text/css">
    #updateTime p {
        margin-top: 15px;
    }

        #updateTime p span {
            margin-left: 15px;
        }

        #updateTime p input {
            width: 60%;
        }
</style>
<div id="Paging">
    <span id="pagercount" style="float:left "></span>
    <div id="pager" class="pager" style="float:left">
    </div>
</div>
<script>
    //下拉框信息
    function GetCategory() {
        $("#sel_Category").html("<option value=\"-1\" code=\"0\">请选择</option>");

        $.ajax({
            type: "GET",
            url: "/Category/GetCategoryName",
            dataType: "json",
            data: {},
            success: function (data) {
                if (data.list != "") {
                    $.each(data.list, function (i, n) {
                        $("#sel_Category").append("<option value='" + n.id + "'>" + n.name + "</option>");
                        $("#sel_leibie").append("<option value='" + n.id + "'>" + n.name + "</option>");
                    });
                }
            }
        });
    }
    function GetSalesMan() {
        $("#sel_salesman").html("<option value=\"-1\" code=\"0\">请选择</option>");

        $.ajax({
            type: "GET",
            url: "/SalesMan/GetSalesManName",
            dataType: "json",
            data: {},
            success: function (data) {
                if (data.list != "") {

                    $.each(data.list, function (i, n) {

                        $("#sel_salesman").append("<option value='" + n.id + "'>" + n.name + "</option>");

                    });
                }
            }
        });
    }
    function GetLevel() {
        $("#sel_level").html("<option value=\"-1\" code=\"0\">请选择</option>");

        $.ajax({
            type: "GET",
            url: "/Level/GetLevelName",
            dataType: "json",
            data: {},
            success: function (data) {
                if (data.list != "") {
                    $.each(data.list, function (i, n) {
                        $("#sel_Level").append("<option value='" + n.id + "' coding=\"" + n.coding + "\">" + n.name + "</option>");
                    });
                }
            }
        });
    }
</script>